OSErr MyConvertToWAV(Movie theMovie, FSSpec *theFile)
{
ComponentInstance myComponent = NULL;
SoundDescriptionHandle myDesc = NULL;
ComponentResult myErr = badComponentType;
// エクスポートコンポーネントを開く: .wav ファイルへのサウンドエクスポータ
myComponent = OpenDefaultComponent(MovieExportType, kQTFileTypeWave);
// コンポーネントが見つからない場合には -2005 エラーを返す
if (myComponent == NULL) goto bail;
// サウンド記述を作成し、値を埋める
myDesc = (SoundDescriptionHandle)NewHandleClear(sizeof(SoundDescription));
if (myDesc == NULL) {
myErr = MemError();
goto bail;
}
// 使用するフォーマット。.wav の dataFormat は次のいずれか。
// k8BitOffsetBinaryFormat または k16BitLittleEndianFormat
(**myDesc).descSize = sizeof(SoundDescription);
(**myDesc).numChannels = 2;
(**myDesc).sampleSize = 8;
(**myDesc).sampleRate = rate22050hz;
(**myDesc).dataFormat = k8BitOffsetBinaryFormat;
// エクスポートコンポーネントに対して、サウンド記述の
// サウンド特性を使用することを伝える
myErr = MovieExportSetSampleDescription(myComponent,
(SampleDescriptionHandle)myDesc,
SoundMediaType);
if (myErr != noErr) goto bail;
// ムービーをファイルにエクスポートする
myErr = ConvertMovieToFile(theMovie, // 変換対象ムービー
NULL, // 全トラック
theFile, // 出力ファイル
kQTFileTypeWave, // ファイルタイプ(.wav)
FOUR_CHAR_CODE('TVOD'), // ファイルのクリエータ
smSystemScript, // スクリプト
NULL, // リソース ID は返さない
0L, // フラグはなし(つまり、「設定」ダイアログはなし)
myComponent); // エクスポートコンポーネント
bail:
// 割り当てた記憶領域があれば解放する
if (myComponent != NULL)
CloseComponent(myComponent);
if (myDesc != NULL)
DisposeHandle((Handle)myDesc);
return myErr;
}
|